<template>
  <!-- 顶部选课组件 -->
  <view class="content" :class="{'select__lesson' : showAdd}">
    <u-tabs
      :class="[is_one?'':'select__lesson__tabs']"
      name="courses_name"
      :showBar="false"
      :activeItemStyle="{ backgroundColor: '#F1F3FF', borderRadius:'36rpx', padding:'0 23rpx'}"
      :current="current"
      :list="courses"
      @change="change"
      :is-scroll="false"
    ></u-tabs>
    <navigator
      v-if="showAdd"
      hover-class="none"
      url="/pages/courseList/courseList"
      class="iconfont icontianjia"
    ></navigator>
  </view>
</template>

<script>
/**
 * selectLesson 课程选择组件 首页与题
 * @property {Boolean} showAdd 是否出现加号可跳转（默认true）
 * @property {Number,String} current 当前选中的第几项
 * @property {Array} list 课程数据列表
 */
import uTabs from "@/components/u-tabs-skin/u-tabs";
import { mapGetters, mapActions } from "vuex";
export default {
  name: "select-lesson",
  components: {
    uTabs
  },
  computed: {
    ...mapGetters(["courses"])
  },
  props: {
    showAdd: {
      type: Boolean,
      default: false
    },
    current: {
      type: [Number, String],
      default: 0
    },
    list: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      is_one: false
    };
  },
  mounted() {
    console.log(this.courses.length);
    if (this.courses.length === 1) {
      this.is_one = true;
    }
  },
  methods: {
    change(index) {
      this.$emit("change", index);
    }
  }
};
</script>

<style lang="scss" scope>
.content {
  /* #ifdef MP-WEIXIN */
  width: 100%;
  height: 72rpx;
  /* #endif */
  margin-bottom: 20rpx;
}
.select__lesson {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  .select__lesson__tabs {
    width: 93%;
  }
  .icontianjia {
    font-size: 34rpx;
  }
}
</style>
